package com.example.algorithm.test;

import org.junit.Test;

/**
 * 5.删除排序数组中的重复项
 * @auther lijiewei
 * @date 2024-03-10 18:19
 */
public class RemoveDuplicates {

    /** 双指针（快慢指针）. */
    private int doublePoint(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        //慢指针
        int i = 0;
        //快指针
        for (int j = 0; j < nums.length; j++) {
            if (nums[i] != nums[j]) {
                i++;
                nums[i] = nums[j];
            }
        }
        return i+1;
    }

    @Test
    public void doublePointTest() throws Exception{
        System.out.println(doublePoint(new int[]{0,1,2,2,3,3,4}));
    }
}
